function B = base_imchanges(VBas, Gx, Gy)
%BASE_IMCHANGES Basis of Image Changes from Flow Bases
%
%   B = base_imchanges(VBas, Gx, Gy);
%
%       Generates the base image changes from flow bases.
%
%       Input arguments:
%       - VBas:         The base velocity fields for a flow family
%       - Gx:           The x-component of the image gradient map
%       - Gy:           The y-component of the image gradient map
%
%       Output arguments:
%       - B:            The array comprised of a set of maps for
%                       image base changes. (size: [h, w, K])
%

% Created by Dahua Lin, on April 5, 2012
%

%% verify input arguments

if ~is_vbasis(VBas)
    error('base_imchanges:invalidarg', ...
        'VBas should be a vector field bases struct.');
end

siz = VBas.size;

if ~(isfloat(Gx) && isreal(Gx) && isequal(size(Gx), siz))
    error('base_imchanges:invalidarg', ...
        'Gx should be a real matrix with size(Gx) == VBas.size');
end

if ~(isfloat(Gy) && isreal(Gy) && isequal(size(Gy), siz))
    error('base_imchanges:invalidarg', ...
        'Gy should be a real matrix with size(Gy) == VBas.size');
end

%% main

Cx = bsxfun(@times, VBas.Bx, Gx(:));
Cy = bsxfun(@times, VBas.By, Gy(:));

B = - (Cx + Cy);
B = reshape(B, [siz, VBas.K]);

